﻿//*************************************************************************************************
// Tests for the CompareContextParams validation rule
//
// Copyright(c) Microsoft Corporation, 2008
//*************************************************************************************************
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WebAndLoadTestPluginsAndRules;
using Microsoft.VisualStudio.TestTools.WebTesting;
using WebAndLoadTestPlugins;

namespace HtmlTagInnerTextTests
{
    /// <summary>
    /// Summary description for ExtractText2Tests
    /// </summary>
    [TestClass]
    public class ExtractText2Tests
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            PageManager.Initialize(testContext);
        }

        public void TestExtractIndex(string startsWith, string endsWith, int index, ExtractText2.SearchResult expectedSearchResult, string expectedString)
        {
            ExtractText2 extractText = new ExtractText2();
            extractText.StartsWith = startsWith;
            extractText.EndsWith = endsWith;
            extractText.Index = index;

            string doc;
            PageManager.Instance.LoadPage("TestPage2.htm", out doc);

            ExtractText2.SearchResult result = extractText.Extract(doc);
            Assert.AreEqual(result, expectedSearchResult);
            if (expectedSearchResult == ExtractText2.SearchResult.Found)
            {
                Assert.AreEqual(extractText.Result, expectedString);
            }
        }

        //[TestMethod]
        [Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItem("webtestrulestests\\testpages\\TestPage2.htm"), TestMethod()]
        public void TestExtractIndex()
        {
            TestExtractIndex("|DMTabPage.aspx?", "|", 0, ExtractText2.SearchResult.Found, "minDT=11/04/2008 00:00:00&maxDT=11/05/2008 01:00:00&ofcCod=P");
            TestExtractIndex("|DMTabPage.aspx?", "|", 1, ExtractText2.SearchResult.Found, "minDT=11/04/2008 00:00:00&maxDT=11/05/2008 01:00:00&ofcCod=S");
            TestExtractIndex("|DMTabPage.aspx?", "|", 2, ExtractText2.SearchResult.Found, "minDT=11/04/2008 00:00:00&maxDT=11/05/2008 01:00:00&ofcCod=G");
            TestExtractIndex("|DMTabPage.aspx?", "|", 3, ExtractText2.SearchResult.Found, "minDT=11/04/2008 00:00:00&maxDT=11/05/2008 01:00:00&ofcCod=O");
            TestExtractIndex("|DMTabPage.aspx?", "|", 4, ExtractText2.SearchResult.Found, "minDT=11/04/2008 00:00:00&maxDT=11/05/2008 01:00:00");
            TestExtractIndex("|DMTabPage.aspx?", "|", 5, ExtractText2.SearchResult.Found, "minDT=11/04/2008 00:00:00&maxDT=11/05/2008 01:00:00&hotRaces=true");
            TestExtractIndex("|DMTabPage.aspx?", "|", 6, ExtractText2.SearchResult.Found, "minDT=11/04/2008 00:00:00&maxDT=11/04/2008 19:00:01");
            TestExtractIndex("|DMTabPage.aspx?", "|", 7, ExtractText2.SearchResult.Found, "minDT=11/04/2008 19:00:01&maxDT=11/04/2008 19:30:01");
            TestExtractIndex("|DMTabPage.aspx?", "|", 8, ExtractText2.SearchResult.Found, "minDT=11/04/2008 19:30:01&maxDT=11/04/2008 20:00:01");
            TestExtractIndex("|DMTabPage.aspx?", "|", 9, ExtractText2.SearchResult.Found, "minDT=11/04/2008 20:00:01&maxDT=11/04/2008 20:30:01");
            TestExtractIndex("|DMTabPage.aspx?", "|", 10, ExtractText2.SearchResult.Found, "minDT=11/04/2008 20:30:01&maxDT=11/04/2008 21:00:01");
            TestExtractIndex("|DMTabPage.aspx?", "|", 11, ExtractText2.SearchResult.Found, "minDT=11/04/2008 21:00:01&maxDT=11/04/2008 22:00:01");
            TestExtractIndex("|DMTabPage.aspx?", "|", 12, ExtractText2.SearchResult.Found, "minDT=11/04/2008 22:00:01&maxDT=11/05/2008 21:00:01");

        }

    }

}
